home *** CD-ROM | disk | FTP | other *** search
- class Swing extends smashing.Renderable
- {
- var arc;
- var pLength;
- var pHalfLength;
- var length;
- var botThresh;
- var pCurrLength;
- var pCurrHalf;
- var x;
- var y;
- var nSwing = 3;
- var cSwing = 0;
- var color = 13333275;
- var cDisable = 0;
- var nDisable = 1;
- var topThresh = 50;
- var hitLength = 0;
- var grabbable = true;
- var bSwung = false;
- function Swing()
- {
- super();
- this.arc = 0.6283185307179586;
- this.pLength = new smashing.Point(0,300);
- this.pHalfLength = new smashing.Point(0,this.pLength.y / 2);
- this.length = this.pLength.y;
- this.botThresh = this.length - 10;
- }
- function update(nElapsed)
- {
- this.cDisable += nElapsed;
- this.cSwing += nElapsed;
- this.cSwing %= this.nSwing;
- var _loc2_ = Math.sin(this.cSwing / this.nSwing * smashing.Phys.TWOPI) * this.arc;
- this.pCurrLength = this.pLength.rotate(_loc2_);
- this.pCurrHalf = this.pHalfLength.rotate(_loc2_ * 0.5);
- }
- function render()
- {
- var _loc2_ = smashing.Viewport.getPos(this);
- this._x = _loc2_.x + smashing.Viewport.centerX;
- this._y = _loc2_.y + smashing.Viewport.centerY;
- this.clear();
- this.lineStyle(4,this.color);
- this.moveTo(0,0);
- if(this.bSwung == true)
- {
- this.lineTo(this.pCurrLength.x,this.pCurrLength.y);
- }
- else
- {
- this.curveTo(this.pCurrHalf.x,this.pCurrHalf.y,this.pCurrLength.x,this.pCurrLength.y);
- }
- }
- function react(oPlayer)
- {
- this.bSwung = true;
- oPlayer.swing(this);
- }
- function checkHit(oPlayer)
- {
- if(this.cDisable > this.nDisable)
- {
- var _loc4_ = new smashing.Point(this.pCurrLength.y,- this.pCurrLength.x);
- _loc4_.normalizeMe();
- var _loc3_ = new smashing.Point(oPlayer.x - this.x,oPlayer.y - this.y);
- var _loc6_ = Math.abs(_loc3_.dot(_loc4_));
- if(_loc6_ > oPlayer.r)
- {
- this.hitLength = 0;
- return false;
- }
- var _loc5_ = this.pCurrLength.normalize();
- var _loc2_ = _loc3_.dot(_loc5_);
- if(_loc2_ < this.topThresh)
- {
- this.hitLength = 0;
- return false;
- }
- if(_loc2_ > this.botThresh)
- {
- this.hitLength = 0;
- return false;
- }
- this.hitLength = _loc2_;
- return true;
- }
- this.hitLength = 0;
- return false;
- }
- }
-